package com.iespring.bean.common;

import com.github.pagehelper.PageInfo;
import com.iespring.bean.admin.goods.po.MallCategory;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author 杨宇健
 * @return
 * @since 2022/12/28 16:24
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CommonData<T> {

    /*limit: 20
    list: [{id: 1152101, goodsSn: "1152101", name: "魔兽世界 部落 奥格瑞玛 拉杆箱 可登机", categoryId: 1012001, brandId: 0,…},…]
    page: 6
    pages: 13
    total: 241*/

    private Integer total;
    private Integer pages;
    private Integer limit;
    private Integer page;
    private List<T> list;
    private List<MallCategory> filterCategoryList;


    public static CommonData data(PageInfo pageInfo) {
        CommonData data = new CommonData();
        data.setTotal((int) pageInfo.getTotal());
        data.setPages(pageInfo.getPages());
        data.setPage(pageInfo.getPageNum());
        data.setLimit(pageInfo.getPageSize());
        data.setList(pageInfo.getList());
        return data;

    }

    public CommonData(Integer total, Integer pages, Integer limit, Integer page, List<T> list) {
        this.total = total;
        this.pages = pages;
        this.limit = limit;
        this.page = page;
        this.list = list;
    }
    //    public static <T> CommonData<T> data(PageInfo<T> pageInfo) {
//        List<T> list   = pageInfo.getList();
//        long total = pageInfo.getTotal();
//        int pageSize = pageInfo.getPageSize();
//        int pages = pageInfo.getPages();
//        int pageNum = pageInfo.getPageNum();
//        return new CommonData<T>((int) total, pages, pageSize, pageNum, list);
//    }
}
